#ifndef __G_TASK_H__
#define __G_TASK_H__

#include <vector>

#include "GDebug.h"
#include "GTypes.h"
#include "GCounter.h"

namespace GEngine
{
	#define G_TASK_MAX_DEPENDENCIES	4

	class GTaskResult;

	enum GTaskPriority
	{
		G_TP_LOW		= 0,
		G_TP_NORMAL		= 1,
		G_TP_HIGH		= 2,
		G_TP_DEFAULT	= G_TP_NORMAL,
	};
	
	class GTask
	{
	friend class GTaskQueue;
	friend class GTaskManager;
	friend class GWorkerThread;
	
	typedef GUtil::GAtomicCounter<> CounterType;

	G_DECLARE_DEBUG_NAME();

	protected:
		GTaskResult*		Result;
		GTaskPriority		Priority;

		bool				ThreadSafe;

		void				IncreaseRef();
		void				DecreaseRef();

	public:
							GTask(GTaskResult* TaskResult, GTaskPriority TaskPriority, bool TaskThreadSafe);
		virtual				~GTask();

		GTaskResult*		GetResult();
		GTaskPriority		GetPriority() const;
		
		bool				CheckThreadSafe() const;

		virtual bool		Spread(GTaskQueue** QueueArr, GSize Count);
		virtual bool		Reduce(OUTPUT GTask** OutTask);
		virtual bool		Divide(OUTPUT GTask** OutTask);

		virtual GUInt32		Execute(GSize WorkerId) = 0;
	};
}

#endif